package com.example.plane;


import android.content.Context;
import android.content.Intent;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import java.util.HashMap;

public class MainActivity extends AppCompatActivity {
//    public SoundPool soundPool= new SoundPool(10, AudioManager.STREAM_SYSTEM,5);
//    public boolean loadover=false;
public static SoundPool soundPool= new SoundPool(20, AudioManager.STREAM_SYSTEM,5);
public static Bitmap[] bitmap=new Bitmap[50];
public  boolean loadover=false;
public static Context context;
public static HashMap<Integer, Integer> soundID = new HashMap<Integer, Integer>();
public static MediaPlayer[] mediaPlayer=new MediaPlayer[10];
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context=this;
//        Thread thread=new Thread(){
//            @Override
//            public void run() {
//                super.run();
//                soundPool.load(MainActivity.context,R.raw.menu,1);
//                try {
//                    this.sleep(10000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                Intent intent = new Intent(MainActivity.this,MenuActivity.class);//打开下一个活动
//                startActivity(intent);
//            }
//        };
//        thread.start();


//播放deep
        musicinit();
        imageinit();
        soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
            @Override
            public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                if(status==0&&sampleId==10) {
                    Intent intent = new Intent(MainActivity.this, MenuActivity.class);//打开下一个活动
                    startActivity(intent);
                    finish();

                }
            }
        });

        try {
            for (int i = 0; i < mediaPlayer.length; i++)
            {mediaPlayer[i].setLooping(true);}
        }catch (Exception e){}

//        mediaPlayer[0].setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
//            @Override
//            public void onPrepared(MediaPlayer mp) {
//                   Intent intent = new Intent(MainActivity.this, MenuActivity.class);//打开下一个活动
//                    startActivity(intent);
//                    finish();
//
//            }
//        });

    }

    public boolean musicinit()
    {
        mediaPlayer[0]=MediaPlayer.create(this,R.raw.big);
        mediaPlayer[1]=MediaPlayer.create(this,R.raw.stage1);
        soundID.put(1, soundPool.load(this, R.raw.big, 1));
        soundID.put(2, soundPool.load(this, R.raw.boom, 1));
        soundID.put(3, soundPool.load(this, R.raw.boss_state, 1));
        soundID.put(4, soundPool.load(this, R.raw.bossfight, 1));
        soundID.put(5, soundPool.load(this, R.raw.bmfristpass, 1));
        soundID.put(6, soundPool.load(this, R.raw.lasereffect, 1));
        soundID.put(7, soundPool.load(this, R.raw.level_end, 1));
        soundID.put(8, soundPool.load(this, R.raw.level_failed, 1));
        soundID.put(9, soundPool.load(this, R.raw.level_main, 1));
        soundID.put(10, soundPool.load(this, R.raw.level_start, 1));
        soundID.put(11, soundPool.load(this, R.raw.menu, 1));
        soundID.put(12, soundPool.load(this, R.raw.select, 1));
        soundID.put(13, soundPool.load(this, R.raw.stage1, 1));
        soundID.put(14, soundPool.load(this, R.raw.stage2, 1));
        soundID.put(15, soundPool.load(this, R.raw.stage3, 1));
        soundID.put(16, soundPool.load(this, R.raw.stage_lose, 1));
        soundID.put(17, soundPool.load(this, R.raw.stage_win, 1));
        soundID.put(18, soundPool.load(this, R.raw.title, 1));
        return  true;
    }
 public  boolean imageinit()
 {
       bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
       bitmap[1] = BitmapFactory.decodeResource(getResources(), R.drawable.heroplane_1);
       bitmap[2] = BitmapFactory.decodeResource(getResources(), R.drawable.shot1);
       bitmap[3] = BitmapFactory.decodeResource(getResources(), R.drawable.ep_2);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//     bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.qj0);
//
//
//


     return  true;
 }

 public  void deviceinit()
 {


 }
}
